package cn.com.bdqn.utils;

import cn.com.bdqn.entity.*;
import com.fasterxml.classmate.TypeResolver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

@EnableOpenApi
@Configuration
public class SwaggerConfiguration {
    private Boolean enable=true;

    @Autowired
    private TypeResolver resolver;

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.OAS_30).pathMapping("/")
                // 定义是否开启swagger，false为关闭，可以通过变量控制
                .enable(enable)
                .groupName("crm")//右上下拉框值
                .apiInfo(new ApiInfoBuilder()
                        .title("标题：客户关系管理系统_接口文档")
                        .description("客户是公司最宝贵的资源，为了更好的发掘老客户的价值，并开发更多新客户，XX公司决定实施客户关系管理系统。希望通过这个系统完成对客户基本信息、联系人信息、交往信息、客户服务信息的充分共享和规范化管理；希望通过对销售机会、客户开发过程的追踪和记录，提高新客户的开发能力；希望在客户将要流失时系统及时预警，以便销售人员及时采取措施，降低损失。并希望系统提供相关报表，以便公司高层随时了解公司客户情况。\n" +
                                "客户服务是一个涉及多个部门，存在一定流程的工作。客户服务水平的高低决定着公司的核心竞争力。该客户关系管理系统应提供一个客户服务在线平台，使客户服务处理过程中相关人员可以在线完成服务的处理和记录工作。")
                        .contact(new Contact("肖凌毅", "主页无", "1638906183@qq.com"))
                        .version("版本号:1.0")
                        .build())
                .additionalModels( resolver.resolve(BasDict.class),resolver.resolve(CstActivity.class),
                        resolver.resolve(CstCustomer.class),resolver.resolve(CstLinkman.class),
                        resolver.resolve(CstLost.class),resolver.resolve(CstService.class),
                        resolver.resolve(Orders.class),resolver.resolve(OrdersLine.class),
                        resolver.resolve(Product.class),resolver.resolve(SalChance.class),
                        resolver.resolve(SalPlan.class),resolver.resolve(Storage.class),
                        resolver.resolve(SysMenu.class),resolver.resolve(SysRole.class),
                        resolver.resolve(SysRoleRight.class),resolver.resolve(SysUser.class))//显示实体类
                .select()
                //.apis(RequestHandlerSelectors.basePackage("com.situ"))
                //.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                //.apis(RequestHandlerSelectors.withMethodAnnotation(Operation.class))
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.regex("/error.*").negate())// 错误路径不监控
                .paths(PathSelectors.any())
                .build();
    }

}